﻿
//加入购物车加减号按钮
$("#minus,#plus").click(function () {
    var type = $(this).attr("id");
    var number = parseInt($("#number").text());
    if (type == "plus") { number++; } else { number <= 1 ? 1 : number--; }
    $("#number").text(number);
})



//加入购物车按钮
$("#goodcard").click(function () {
    var strKey = "";
    var txtGoodID = $("#txtGoodID");
    var getData = "";
    for (var i = 0; i < localStorage.length; i++) {
        strKey = localStorage.key(i);        
        if (strKey.substring(0, 5) == "good_") {
            getData = JSON.parse(xxl.xd.getValue(strKey));
            if (getData.MicroGoodsID == txtGoodID.val()) { break; } else { getData = ""; }
        }
    }
    if (getData == "") {//新增
        var goodlist = new Object();
        goodlist.Type = "good_" + retRndNum(3);
        goodlist.MicroGoodsID = txtGoodID.val();
        goodlist.ConvertNumber = $("#number").text();
        xxl.xd.setValue(goodlist.Type, JSON.stringify(goodlist));
    } else { //编辑
        getData.ConvertNumber = parseInt(getData.ConvertNumber) + parseInt($("#number").text());
        xxl.xd.setValue(getData.Type, JSON.stringify(getData));
    }
    var cookieStr = "";
    for (var i = 0; i < localStorage.length; i++) {
        strKey = localStorage.key(i);
        if (strKey.substring(0, 5) == "good_") {
            getData = JSON.parse(xxl.xd.getValue(strKey));
            cookieStr += getData.MicroGoodsID + ',' + getData.ConvertNumber + '|';
        }
    }
    setCookie("goodlist", cookieStr);
    var result = confirm("添加成功,是否进行结算？");
    if (result) { $("#go").click(); } else { $("#goBack").click(); }
})
